package com.jin.spirng_boot_learn.ioc;

import com.jin.spirng_boot_learn.ioc.beans.HaoHuaShip;
import com.jin.spirng_boot_learn.ioc.beans.Ship;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import java.util.Arrays;

public class ApplicaitonRun {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(Appconfig.class);
        Ship ship = (Ship) applicationContext.getBean("ship");
        HaoHuaShip haoHuaShip = (HaoHuaShip) applicationContext.getBean("haoHuaShip");
        System.out.println("------------------------------------------------");
        applicationContext.close();
//        getAllBeans(applicationContext);
    }

    private static void getAllBeans(AnnotationConfigApplicationContext context) {
        Arrays.stream(context.getBeanDefinitionNames())
                .forEach((String name)->System.out.println(context.getBean(name)));
    }
}

